﻿@model IEnumerable<DataAccess.DB.SanPhamInKho>

@{   
    Layout = null;
    ViewBag.Title = "Sản phẩm";
}

<table id="jqgDataSP"></table>
<div id="jqgpDataSP"></div>

<script type="text/javascript">
    $(document).ready(function () {
        loadGridSP();
        $("#gs_Action").hide();
        $("#gs_GiaNhap").hide();
        $("#gs_SoLuong").hide();
        $("#gs_DonVi").hide();
    });

    function loadGridSP() {
        $('#jqgDataSP').setGridParam({ datatype: "json" }).trigger('reloadGrid');
        $("#jqgDataSP").jqGrid({
            url: '@Url.Action("SanPhamTheoKho", "SanPhamIKho")',
            hoverrows: true,
            datatype: 'json',
            mtype: 'POST',

            colNames: ['ID', 'Action', 'Mã sản phẩm', 'Giá nhập', 'Số lượng', 'Đơn vị tính'],
            colModel: [
                        { name: 'ID', index: 'ID', align: 'center', hidden: true },
                        { name: 'Action', index: 'Action', align: 'center', editable: true, formatter: ActionChonSP, width: '40px' },
                        { name: 'MaSP', index: 'MaSP', align: 'left', width: '300px' },
                        { name: 'SoLuong', index: 'SoLuong', align: 'left', width: '95px' },
                        { name: 'DonVi', index: 'DonVi', align: 'right', width: '65px' },
                        { name: 'GiaNhap', index: 'GiaNhap', align: 'right', width: '65px' }
            ],
            pager: '#jqgpDataSP',
            jsonReader: { repeatitems: false },
            sortname: 'MaSP',
            viewrecords: true,
            sortorder: 'desc',
            height: 'auto',
            autoencode: true,
            rowNum: 20,
            rowList: [5, 10, 20],

        });
        $("#jqgDataSP").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn", enableClear: false, ignoreCase: true });
        function ActionChonSP(cellvalue, options, rowObject) {
            var rowid = rowObject["ID"];
            return "<input style='height:22px;' type='button' value='Chọn' onclick='SelectSP(" + rowid + ")'  />";
        };

    }
</script>
